/******************************************************************************
 * Copyright 2023 The Apollo Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#include "modules/canbus_vehicle/x3epro/protocol/vcu_vehicle_status_report_200.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"

namespace apollo {
namespace canbus {
namespace x3epro {

using ::apollo::drivers::canbus::Byte;

Vcuvehiclestatusreport200::Vcuvehiclestatusreport200() {}
const int32_t Vcuvehiclestatusreport200::ID = 0x200;

void Vcuvehiclestatusreport200::Parse(const std::uint8_t* bytes, int32_t length,
                         X3epro* chassis) const {
  chassis->mutable_vcu_vehicle_status_report_200()->set_drive_enable_resp(drive_enable_resp(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_highvoltagecircuitstate(vcu_highvoltagecircuitstate(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_dcdc_enabledstates(vcu_dcdc_enabledstates(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_control_mode_resp(control_mode_resp(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_vehicle_speed(vcu_vehicle_speed(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_lowbatterychargingfunctionstate(vcu_lowbatterychargingfunctionstate(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_display_soc(vcu_display_soc(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_motor_speed(vcu_motor_speed(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_motor_direction(vcu_motor_direction(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_motor_speed_valid(vcu_motor_speed_valid(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_statusrept_alivecounter(vcu_statusrept_alivecounter(bytes, length));
  chassis->mutable_vcu_vehicle_status_report_200()->set_vcu_statusrept_checksum(vcu_statusrept_checksum(bytes, length));
}

// config detail: {'bit': 0, 'enum': {0: 'DRIVE_ENABLE_RESP_INVALID', 1: 'DRIVE_ENABLE_RESP_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'drive_enable_resp', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Drive_enable_respType Vcuvehiclestatusreport200::drive_enable_resp(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(0, 1);

  Vcu_vehicle_status_report_200::Drive_enable_respType ret =  static_cast<Vcu_vehicle_status_report_200::Drive_enable_respType>(x);
  return ret;
}

// config detail: {'bit': 2, 'enum': {0: 'VCU_HIGHVOLTAGECIRCUITSTATE_DISCONNECT', 1: 'VCU_HIGHVOLTAGECIRCUITSTATE_CONNECT'}, 'is_signed_var': False, 'len': 1, 'name': 'vcu_highvoltagecircuitstate', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Vcu_highvoltagecircuitstateType Vcuvehiclestatusreport200::vcu_highvoltagecircuitstate(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(2, 1);

  Vcu_vehicle_status_report_200::Vcu_highvoltagecircuitstateType ret =  static_cast<Vcu_vehicle_status_report_200::Vcu_highvoltagecircuitstateType>(x);
  return ret;
}

// config detail: {'bit': 3, 'enum': {0: 'VCU_DCDC_ENABLEDSTATES_DISABLE', 1: 'VCU_DCDC_ENABLEDSTATES_ENABLE'}, 'is_signed_var': False, 'len': 1, 'name': 'vcu_dcdc_enabledstates', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Vcu_dcdc_enabledstatesType Vcuvehiclestatusreport200::vcu_dcdc_enabledstates(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(3, 1);

  Vcu_vehicle_status_report_200::Vcu_dcdc_enabledstatesType ret =  static_cast<Vcu_vehicle_status_report_200::Vcu_dcdc_enabledstatesType>(x);
  return ret;
}

// config detail: {'bit': 6, 'enum': {0: 'CONTROL_MODE_RESP_STANDBY', 1: 'CONTROL_MODE_RESP_AUTO_DRIVE', 2: 'CONTROL_MODE_RESP_NET_DRIVE', 3: 'CONTROL_MODE_RESP_REMOTE_CONTROL', 4: 'CONTROL_MODE_RESP_EMERGENCY_BRAKE'}, 'is_signed_var': False, 'len': 3, 'name': 'control_mode_resp', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Control_mode_respType Vcuvehiclestatusreport200::control_mode_resp(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 0);
  int32_t x = t0.get_byte(4, 3);

  Vcu_vehicle_status_report_200::Control_mode_respType ret =  static_cast<Vcu_vehicle_status_report_200::Control_mode_respType>(x);
  return ret;
}

// config detail: {'bit': 15, 'is_signed_var': False, 'len': 13, 'name': 'vcu_vehicle_speed', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': 'Km/h ->  m/s', 'precision': 0.05625, 'type': 'double'}
double Vcuvehiclestatusreport200::vcu_vehicle_speed(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 1);
  int32_t x = t0.get_byte(0, 8);

  Byte t1(bytes + 2);
  int32_t t = t1.get_byte(3, 5);
  x <<= 5;
  x |= t;

  double ret = x * 0.056250 / 3.6;
  return ret;
}

// config detail: {'bit': 17, 'enum': {0: 'VCU_LOWBATTERYCHARGINGFUNCTIONSTATE_RESERVED', 1: 'VCU_LOWBATTERYCHARGINGFUNCTIONSTATE_START', 2: 'VCU_LOWBATTERYCHARGINGFUNCTIONSTATE_STOP', 3: 'VCU_LOWBATTERYCHARGINGFUNCTIONSTATE_INVALID'}, 'is_signed_var': False, 'len': 2, 'name': 'vcu_lowbatterychargingfunctionstate', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Vcu_lowbatterychargingfunctionstateType Vcuvehiclestatusreport200::vcu_lowbatterychargingfunctionstate(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 2);
  int32_t x = t0.get_byte(0, 2);

  Vcu_vehicle_status_report_200::Vcu_lowbatterychargingfunctionstateType ret =  static_cast<Vcu_vehicle_status_report_200::Vcu_lowbatterychargingfunctionstateType>(x);
  return ret;
}

// config detail: {'bit': 31, 'is_signed_var': False, 'len': 8, 'name': 'vcu_display_soc', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int Vcuvehiclestatusreport200::vcu_display_soc(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 3);
  int32_t x = t0.get_byte(0, 8);

  int ret = x;
  return ret;
}

// config detail: {'bit': 39, 'is_signed_var': False, 'len': 16, 'name': 'vcu_motor_speed', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 0.25, 'type': 'double'}
double Vcuvehiclestatusreport200::vcu_motor_speed(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 4);
  int32_t x = t0.get_byte(0, 8);

  Byte t1(bytes + 5);
  int32_t t = t1.get_byte(0, 8);
  x <<= 8;
  x |= t;

  double ret = x * 0.250000 / 3.6;
  return ret;
}

// config detail: {'bit': 54, 'enum': {0: 'VCU_MOTOR_DIRECTION_STANDBY_STATUS', 1: 'VCU_MOTOR_DIRECTION_FORWARD_MODE', 2: 'VCU_MOTOR_DIRECTION_REVERSE_MODE'}, 'is_signed_var': False, 'len': 2, 'name': 'vcu_motor_direction', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Vcu_motor_directionType Vcuvehiclestatusreport200::vcu_motor_direction(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(5, 2);

  Vcu_vehicle_status_report_200::Vcu_motor_directionType ret =  static_cast<Vcu_vehicle_status_report_200::Vcu_motor_directionType>(x);
  return ret;
}

// config detail: {'bit': 55, 'enum': {0: 'VCU_MOTOR_SPEED_INVALID', 1: 'VCU_MOTOR_SPEED_VALID'}, 'is_signed_var': False, 'len': 1, 'name': 'vcu_motor_speed_valid', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Vcu_vehicle_status_report_200::Vcu_motor_speed_validType Vcuvehiclestatusreport200::vcu_motor_speed_valid(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(7, 1);

  Vcu_vehicle_status_report_200::Vcu_motor_speed_validType ret =  static_cast<Vcu_vehicle_status_report_200::Vcu_motor_speed_validType>(x);
  return ret;
}

// config detail: {'bit': 51, 'is_signed_var': False, 'len': 4, 'name': 'vcu_statusrept_alivecounter', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Vcuvehiclestatusreport200::vcu_statusrept_alivecounter(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 6);
  int32_t x = t0.get_byte(0, 4);

  int ret = x;
  return ret;
}

// config detail: {'bit': 63, 'is_signed_var': False, 'len': 8, 'name': 'vcu_statusrept_checksum', 'offset': 0.0, 'order': 'motorola', 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int Vcuvehiclestatusreport200::vcu_statusrept_checksum(const std::uint8_t* bytes, int32_t length) const {
  Byte t0(bytes + 7);
  int32_t x = t0.get_byte(0, 8);

  int ret = x;
  return ret;
}
}  // namespace x3epro
}  // namespace canbus
}  // namespace apollo
